<template>
    <div class="tab-bar-item" :style="activeStyle" @click="itemClick">
        <!-- 插槽 -->
        <div v-if="!isActive"><slot name="item-icon"></slot></div>
        <div v-else><slot name="item-icon-active"></slot></div>
        <div><slot name="item-text" class="text"></slot></div>
        <div v-if="!isActive"></div>
        <div v-else class="arrow" ></div>
    </div>
</template>

<script>
export default {
    name: 'TabBarItem',
    //父传子数据用props接收
    props: {
        path: String,
        activeColor:{
            type: String,
            default: 'rgb(240, 180, 69)'
        }
    },
    //计算属性
    computed: {
        //判断活跃的页面路径是否是当前选项的路径
        isActive() {
            return this.$route.path.indexOf(this.path) != -1;
        },
        //是活跃页面时修改图标和文字颜色
        activeStyle() {
            return this.isActive ? {"background-color":this.activeColor} : {}
        }
    },
    data() {
        return {
            // isActive: true,
        };
    },
    methods: {
        //点击跳转到相应的路由路径界面展示
        itemClick() {
            this.$router.replace(this.path).catch(() => {});
        },
    },
};
</script>

<style>
    /* 导航中每个选项的样式 */
    .tab-bar-item{
        color: white;
        text-align: center;
        line-height: 40px;
        height: 130px;
        width: 120px;
        background-color: rgb(60, 138, 168);
        border-radius: 8%;
        cursor:pointer;
    }

    /* 设置每个选项图片样式 */
    .tab-bar-item img{
        height: 50px;
        width: 50px;
        margin-top: 25px;
        vertical-align: middle;  /**去除图片下的空白区 */
    }

    .arrow {   
        width: 0px;   
        height: 0px;   
        border-left: 10px solid transparent;   
        border-top: 10px solid;   
        border-right: 10px solid transparent;   
        position: absolute;   
        margin-left: 50px;
        margin-top: 15px;
        border-top-color: rgb(240, 180, 69);   
    }   
</style>